package com.yilu.driver.mvp.presenter;

import android.content.Context;
import android.widget.Toast;

import com.is.common.retrofitrxcache.RxCacheResult;
import com.is.common.rx.RxSubscriber;
import com.yilu.driver.entity.LoginResponse;
import com.yilu.driver.mvp.contract.LoginContract;

import org.json.JSONObject;


public class LoginPresenter extends LoginContract.Presenter {
    private Context mContext;

    public LoginPresenter(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public void sendLogin(JSONObject json) {
        mRxManager.add(mModel.login(json)
                .subscribe(new RxSubscriber<RxCacheResult<LoginResponse>>(
                        mContext, "登录中", true) {
                    @Override
                    public void onStart() {
                        super.onStart();
                    }

                    @Override
                    protected void _onNext(RxCacheResult<LoginResponse> loginResponseRxCacheResult) {
                        mView.returnLogin(loginResponseRxCacheResult.getResultModel());
                    }

                    @Override
                    protected void _onError(String message) {
                        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
                    }
                }));
    }
}
